package com.ruoyi.project.bill.controller;


import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.bill.domain.BillListener;
import com.ruoyi.project.bill.service.IBillListenerService;
import lombok.extern.slf4j.Slf4j;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 单据动作监听Controller
 * 
 * @author ruoyi
 * @date 2025-07-03
 */
@RestController
@RequestMapping("/listener")
@Slf4j
public class BillListenerController extends BaseController {
    @Autowired
    private IBillListenerService billListenerService;

    /**
     * 查询单据动作监听列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BillListener billListener) {

        startPage();
        List<BillListener> list = billListenerService.selectBillListenerList(billListener);
        return getDataTable(list);
    }

    /**
     * 导出单据动作监听列表
     */
    @Log(title = "单据动作监听", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BillListener billListener) {

        List<BillListener> list = billListenerService.selectBillListenerList(billListener);
        ExcelUtil<BillListener> util = new ExcelUtil<BillListener>(BillListener.class);
        util.exportExcel(response, list, "单据动作监听数据");
    }

    /**
     * 获取单据动作监听详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(billListenerService.selectBillListenerById(id));
    }

    /**
     * 新增单据动作监听
     */
    @Log(title = "单据动作监听", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BillListener billListener) {
        String msg = billListenerService.insertBillListener(billListener);
        return StringUtils.isNull(msg) || StringUtils.isEmpty(msg) ? success() : error(msg);
    }

    /**
     * 修改单据动作监听
     */
    @Log(title = "单据动作监听", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BillListener billListener) {
        String msg = billListenerService.updateBillListener(billListener);
        return StringUtils.isNull(msg) || StringUtils.isEmpty(msg) ? success() : error(msg);
    }

    /**
     * 删除单据动作监听
     */
    @Log(title = "单据动作监听", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        String msg = (billListenerService.deleteBillListenerByIds(ids));
        return StringUtils.isNull(msg) || StringUtils.isEmpty(msg) ? success() : error(msg);
    }
}



